﻿namespace Ecreate.Data
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;
    using System.Reflection;
    public sealed class QueryParameterCollection : CollectionBase
    {
        private int intitialCapacity;

        public QueryParameterCollection()
        {
            this.intitialCapacity = 10;
        }

        public QueryParameterCollection(int initCapacity)
        {
            this.intitialCapacity = 10;
            this.intitialCapacity = initCapacity;
        }

        public QueryParameter Add(QueryParameter param)
        {
            base.InnerList.Add(param);
            return param;
        }

        public QueryParameter Add(string ParameterName, object Value)
        {
            return this.Add(new QueryParameter(ParameterName, Value));
        }

        public int IndexOf(string ParameterName)
        {
            if (base.InnerList != null)
            {
                for (int i = 0; i < base.InnerList.Count; i++)
                {
                    if (((QueryParameter)base.InnerList[i]).ParameterName.Equals(ParameterName))
                    {
                        return i;
                    }
                }
            }
            return -1;
        }

        private void RangeCheck(int index)
        {
            if ((index < 0) || (base.Count <= index))
            {
                throw new IndexOutOfRangeException("Number " + index.ToString() + " is out of Range");
            }
        }

        private int RangeCheck(string ParameterName)
        {
            int num1 = this.IndexOf(ParameterName);
            if (num1 < 0)
            {
                throw new IndexOutOfRangeException("ParameterName " + ParameterName + " dose not exist");
            }
            return num1;
        }

        private void Replace(int index, QueryParameter newValue)
        {
            this.Validate(index, newValue);
            base.InnerList[index] = newValue;
        }

        private void Validate(int index, QueryParameter param)
        {
        }

        private void ValidateType(QueryParameter param)
        {
        }

        public QueryParameter this[string ParameterName]
        {
            get
            {
                int num1 = this.RangeCheck(ParameterName);
                return (QueryParameter)base.InnerList[num1];
            }
            set
            {
                int num1 = this.RangeCheck(ParameterName);
                this.Replace(num1, value);
            }
        }

        public QueryParameter this[int index]
        {
            get
            {
                this.RangeCheck(index);
                return (QueryParameter)base.InnerList[index];
            }
            set
            {
                this.RangeCheck(index);
                this.Replace(index, value);
            }
        }
    }
}
